# -*- coding: utf-8 -*-
"""
date: Tue Dec 11 10:22:05 2018
python: Anaconda 3.6.5
author: kanade
email: kanade@blisst.cn
"""
import numpy as np


# dtype = (变长类型, 维度)  和  dtype = 类型字符串
# array([[1, 2, 3, 4]], dtype=int8)
i1 = np.array(['1234'], dtype=(np.int8,4))
i2 = np.array(['1234'], dtype='4i1')
i3 = np.array(['1234'], dtype='(4,)i1')
i4 = np.array([(1,2,3,4)], dtype=(np.int8, 4))
# array([[[1, 2],[3, 4]]])
i5 = np.array([((1, 2), (3, 4))], dtype=(np.int8, (2,2)))
# array([[1., 2., 3., 4.]], dtype=float16)
f1 = np.array(['1234'], dtype=(np.float16,4))
f2 = np.array(['1234'], dtype='4f2')
# array([['1', '2', '3', '4']], dtype='<U1')
s1 = np.array(['1234'], dtype='4U1')
# array(['1234'], dtype='<U4')
s2 = np.array(['1234'], dtype='U4')

# 将('1234', (1,2,3,4))当成一个元素，而'U4, 4i4'是这个元素的类型
s3 = np.array([('1234', (1,2,3,4))], dtype='U4, 4i4')
#print(h, h.dtype, h[0]['f0'], h[0]['f1'])
# f0 f1 为默认命名，可以修改，如下

# dtype={'names':[字段名称表], 'formats':[字段类型]}
a = np.array([('1234', (1,2,3,4)), ('5678', (5,6,7,8))],
              dtype={'names':['小','大'],'formats':['U4', '4i4']})
# dtype=[(字段名称,字段类型,字段维度),...]
b = np.array([('1234', (1,2,3,4)), ('5678', (5,6,7,8))],
              dtype=[('小','U4',1),('大','i4',4)])
# dtype={字段名称:(字段类型,字节数),...}
c = np.array([('1234', (1,2,3,4)), ('5678', (5,6,7,8))],
              dtype={'小':('U4',0),'大':('4i4',16)})


e = np.array([0x1234],dtype=('>u2', {'lo': ('u1', 0),'hi': ('u1', 1)}))
# 将一个16进制数解读为两个一字节的无符号整数
# 使用{:x}是为了和0x1234比较，否则出来的就是12 34的16进制数了
#print('{:x}'.format(e[0]))
#print('{:x} {:x}'.format(e['lo'][0], e['hi'][0]))





